<template>
	<view class="community">
		<view class="head_bg" style="height: 280rpx;">
			<view class="ele_title_left padding-left-sm padding-bottom-xs">
				<view class="ele_title_inner padding-xs">
					<image class="ele_address_img" src="../../common/img/gongsi_bai.png" mode=""></image>
				    <text class="text-white">{{info.residential_quarters_name}}</text></view>
				<view class="ele_address padding-xs">
					<image class="ele_address_img" src="../../common/img/dizhi_bai.png" mode=""></image>
					<text class="text-white">{{info.residential_quarters_address}}</text>
				</view>
			</view>
		</view>
		<view class="big_box" style="height: auto;">
			<view class="big_box_inner">
				<view class="big_inner_one" style="margin-bottom:20rpx;" v-for="(info,index) in list" :key="index" @click="toDetail(info.set_meal_guid)">
					<view class="flex padding-sm padding-top-xs padding-bottom-xs border">
						<view class="flex-sub  package-title">{{info.package_name}}</view>
						<view class="flex-sub text-right">
							<image @click.stop="del(info.set_meal_guid)" src="../../common/img/delxq.png" style="width:99rpx;height:85rpx;vertical-align: middle"></image>					
						</view>
					</view>
					<!-- <view class="flex">
						<view class="flex-sub padding-sm">每日充电次数：{{info.user_num}}次</view>
						<view class="flex-sub padding-sm text-right">购买次数：{{info.bug_num}}次</view>
					</view>
					<view class="flex border">
						<view class="flex-sub padding-sm">每次充电时长：{{info.charging_time}}小时</view>
						<view @tap="tobuylist(info.set_meal_guid,info.package_name)" class="flex-sub padding-sm text-right" style="color: #3A9EFF;">购买记录</view>
					</view> -->
					<view class="operating_box_inner">
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;">{{info.user_num}}</view>
							<view class="money_details_text" style="color: #666666;">总次数(次)</view>
						</view>
						<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;">{{info.user_num}}</view>
							<view class="money_details_text" style="color: #666666;">每日充电(次)</view>
						</view>
						<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;">{{info.charging_time}}</view>
							<view class="money_details_text" style="color: #666666;">每次充电(时)</view>
						</view>
					</view>
					<view class="operating_box_inner padding-bottom-sm">
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;">{{info.bug_num}}</view>
							<view class="money_details_text" style="color: #666666;">购买量(次)</view>
						</view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;">{{info.charging_method==0?'按时长':'按次数'}}</view>
							<view class="money_details_text" style="color: #666666;">收费方式</view>
						</view>
						<view class="money_details_inner money_details_inner1">
							<view class="money_details_number" style="color: #333333;"></view>
							<view @tap="tobuylist(info.set_meal_guid,info.package_name)" class="flex-sub padding-sm " style="color: #3A9EFF;">购买记录</view>
						</view>
						
					</view>
					<view class="flex border-top">
						<view class="flex-sub padding-sm text-right">
							<text>套餐费：<text class="text-red text-lg">¥{{info.package_price}}元</text>/月</text>
							<text class="padding-left-lg">销售：<text class="text-red">¥{{info.bug_money}}</text></text>
						</view>
					</view>
				</view>
				<view style="height:100rpx;"></view>
				<view v-if="list.length==0" class="margin-top-lg text-center">
					<image src='../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
				</view>
			</view>
		</view>
		<image @tap="toAdd" class="add_btn" src="../../common/img/tianjia.png" mode=""></image>
		<view style="height:100rpx;"></view>		
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				info:{},
				list:[],
				loadingTxt:'加载更多',
				inputval:"",
				/* iconname:"unfold", */
			}
		},
		onLoad(e) {
			this.info=JSON.parse(e.info)
		},
		onShow() {
			page=1;
			this.gatdata();
		},
		methods: {
			searchShop(){
				page=1;
				this.gatdata();
			},
			gatdata(){
				let that=this;
				that.http.tokenreq({
					url: 'setmeal/v1/list',
					data:{"pageindex":page,
					      "residential_quarters_guid":this.info.residential_quarters_guid
					}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						let list=e.rows;
						that.list=list;
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'setmeal/v1/list',
					data:{"pageindex":page,
					      "residential_quarters_guid":this.info.residential_quarters_guid
					}
				}).then((res) => {
					uni.hideLoading();
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
				// this.getMoreNews()
			},
			//新增
			toAdd(){
				uni.navigateTo({
					url: '/pages/index/addPackage?info='+JSON.stringify(this.info)
				})
			},
			toDetail(id){
				uni.redirectTo({
					url:"/pages/index/addPackage?id="+id+"&info="+JSON.stringify(this.info)
				})
			},
			//购买记录
			tobuylist(id,name){
				uni.navigateTo({
					url:"/pages/index/buy_list?id="+id+"&info="+JSON.stringify(this.info)+"&name="+name
				})
			},
			//删除小区
			delCommunity(guid){
				let that=this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该小区信息吗?',
					success: function (res) {
						if (res.confirm) {
							that.del(guid);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			del(guid){
				let that=this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该数据吗?',
					success: function (res) {
						if (res.confirm) {
							that.suredel(guid);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			suredel(guid){
				let that=this;
				uni.showLoading();
				that.http.tokenreq({
					url: 'setmeal/v1/del',
					data:{"set_meal_guid":guid}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.hideLoading();
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									page=1;
									that.gatdata()
								}
							}
						});
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			}
		}
	}
</script>
<style>
	.detail_br{
		height:60rpx !important;
	}
	.big_inner_two{
		margin-bottom: 0px;
	}
	page{
		background-color: #FFFFFF;
	}
	.big_inner_one{
		padding: 0;
	}
	.package-title{
		color: #000000;
		font-size: 32rpx;
		vertical-align: middle
	}
	.border{
		border-bottom: 2rpx dotted #EEEEEE;
	}
	.border-top{
		border-top: 2rpx dotted #EEEEEE;
	}
</style>
